# Contributor: Nicolas Lorin <androw95220@gmail.com>
# Contributor: Danct12 <danct12@disroot.org>
# Maintainer: Danct12 <danct12@disroot.org>
pkgname=fceux
pkgver=2.6.6
pkgrel=2
pkgdesc="Fast and ultra-compatible NES/Famicom emulator"
url="https://fceux.com"
arch="all"
license="GPL-2.0-only"
makedepends="
	cmake
	clang-dev
	ffmpeg-dev
	lua5.1-dev
	mesa-dev
	minizip-dev
	qt6-qtbase-dev
	samurai
	sdl2-dev
	zlib-dev
	"
subpackages="$pkgname-doc"
source="$pkgname-$pkgver.tar.gz::https://github.com/TASEmulators/fceux/archive/refs/tags/v$pkgver.tar.gz
	01-rdtsc.patch"
options="!check" # no testsuite

build() {
	if [ "$CBUILD" != "$CHOST" ]; then
		CMAKE_CROSSOPTS="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi

	case "$CARCH" in
	aarch64|arm*)
		# for some reason we have to manually pass this. i guess because
		# the default is just GL?
		export CXXFLAGS="$CXXFLAGS -DQT_OPENGL_ES_2"
		;;
	esac

	cmake -B build -G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DBUILD_SHARED_LIBS=True \
		-DCMAKE_BUILD_TYPE=MinSizeRel \
		-DQT6=ON \
		$CMAKE_CROSSOPTS
	cmake --build build
}

package() {
	DESTDIR="$pkgdir" cmake --install build
	install -d "$pkgdir/usr/share/doc/$pkgname"
	cp -r documentation/* "$pkgdir/usr/share/doc/$pkgname/"
	install -Dm644 changelog.txt -t "$pkgdir/usr/share/doc/$pkgname/"
	rm -f "$pkgdir/usr/share/$pkgname/"*.dll
}

sha512sums="
0a6cff4c6b900569978003675812d92d893281c2bdf3b0b58c07e257251648ee325f9bb29b01253ab1a5e9354631d91a6e67a1e6bb36ebe89d5067509cabfa64  fceux-2.6.6.tar.gz
7ebd367bec7799023cf6a4fc95c93161760e33881bc2f705ef664758292066e8a49c7c774b0df7f7587eb913c5d2816caf49d9e15d1b165dc7d93dd7e4e59f23  01-rdtsc.patch
"
